/**
 * Aug 8, 2020  copy right
 */
package com.code260.ss.spring3mybatis.demo.infra.db;

import java.util.Collection;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

/**
 * @author code260@qq.com
 *
 */
public class PreciseModuloShardingTableAlgorithm implements PreciseShardingAlgorithm<String> {

	@Override
	public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<String> shardingValue) {
		for (String each : availableTargetNames) {
			if (each.endsWith(shardingValue.getValue().hashCode() % 4 + "")) {
				return each;
			}
		}
		throw new UnsupportedOperationException();
	}

}
